package com.r_z.mapper;

import com.r_z.entity.OrderDetails;
import com.r_z.entity.SalesOrder;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author z
 * @version 1.0
 * @date 2023/5/29
 */
@Mapper
public interface SalesOrderMapper {
    /**查询销售订单*/
    @Select("select * from salesOrder ${strWhere} limit #{page},#{limit}")
    List<SalesOrder> salesOrderList(@Param("strWhere") String strWhere, @Param("page")int page, @Param("limit") int limit);

    @Select("select count(*) from salesOrder ${strWhere} ")
    int count(String strWhere);

    /**增加销售订单*/
    @Insert("INSERT INTO salesOrder(salesOrderId,salesOrderNum,totalDetails,paymentState,deliveryStatus,nowTime)" +
            "VALUES(#{salesOrderId},#{salesOrderNum},#{totalDetails},#{paymentState},#{deliveryStatus},#{nowTime})")
    int insertSalesOrder(SalesOrder salesOrder);
    /**修改销售订单*/
    @Update("update salesOrder set salesOrderNum=#{salesOrderNum},totalDetails=#{totalDetails}," +
            "paymentState=#{paymentState},deliveryStatus=#{deliveryStatus},nowTime=#{nowTime} where salesOrderId=#{salesOrderId}")
    int  updateSalesOrder(SalesOrder salesOrder);
    /**删除销售订单*/
    @Delete("delete from salesOrder where salesOrderId=#{salesOrderId}")
    int deleteSalesOrder(String salesOrderId);
    /**
     * 销售订单详情
     * @param salesOrderId
     * @return
     */
@Select("SELECT p.productId,od.quantity,od.price,od.totalDetails,od.salesOrderId" +
        " FROM orderDetails od JOIN product p ON od.productId =p.productId  WHERE od.salesOrderId =#{salesOrderId}")
    List<OrderDetails> orderList(String salesOrderId);
}

